﻿@model System.Data.DataTable
@using Wheeler.Domain;
@using Wheeler.Common.DB;
@using Wheeler.Common.Extensions;
@using Wheeler.Web.ViewModels;

@{
    String listType = ViewData[AppConstants.ViewDataKeys.LIST_TYPE] as String;
    bool _IsTabularList = false;
    if (String.Compare(listType, "T", true) == 0){
        _IsTabularList = true;
    }
}

@if (Model != null && Model.Rows.Count > 0)    
{
    if (_IsTabularList)
    {
        <table class="data-table-list" cellpadding="0" cellspacing="0">
            <tr>
                <th>Registration No</th>
                <th>Chassis No</th>
                <th>Engine No</th>
                <th>Owner Name</th>
                @*<th>Test Status</th>*@
                <th>Action</th>
            </tr>
        @foreach (System.Data.DataRow _Row in Model.Rows)
        {
            int _ID = NullHandler.GetInt(_Row["ID"]);
            int _VehicleID = NullHandler.GetInt(_Row["VehicleID"]);
            bool _HasPublished = NullHandler.GetBoolean(_Row["HasPublished"]);
            bool _HasConfirmed = NullHandler.GetBoolean(_Row["HasConfirmed"]);
            <tr>
                <td>@NullHandler.GetString(_Row["RegistrationNo"])</td>
                <td>@NullHandler.GetString(_Row["ChasisNo"])</td>
                <td>@NullHandler.GetString(_Row["EngineNo"])</td>
                <td>@NullHandler.GetString(_Row["OwnerName"])</td>
                @*<td>@MvcHtmlString.Create(WebUtil.GetTestStatusString(NullHandler.GetInt(_Row["TestStatus"])))</td>*@
                <td>
                    <a class="btn btn-mini" href="/Private/TestResult/Confirm/@_ID?VehicleID=@_VehicleID"><i class="icon-print"></i> Print</a>                    
                    @if (UserInfo.CanEditTestResult(_HasConfirmed, _HasPublished)) {
                        <a class="btn btn-mini" href="/Private/TestResult/Edit/@_ID?VehicleID=@_VehicleID"><i class="icon-edit"></i> Edit</a>
                    }
                </td>
            </tr>
        }
        </table>
    }
    else
    {
        //Normal Non Tabular Listing
        foreach (System.Data.DataRow _Row in Model.Rows)
        {
            int _ID = NullHandler.GetInt(_Row["ID"]);
            int _VehicleID = NullHandler.GetInt(_Row["VehicleID"]);
            bool _HasPublished = NullHandler.GetBoolean(_Row["HasPublished"]);
            bool _HasConfirmed = NullHandler.GetBoolean(_Row["HasConfirmed"]);
            <div class="jb-job">
                <div><strong>@NullHandler.GetString(_Row["RegistrationNo"])</strong></div>
                <div class="jb-label-hint">                    
                    Test Performed On @NullHandler.GetDateTime(_Row["TestPerformedOn"]).ToString("MMMM dd, yyyy")
                </div>
                <div class="para">
                    Chassis No: @NullHandler.GetString(_Row["ChasisNo"])<br />
                    Engine No: @NullHandler.GetString(_Row["EngineNo"])<br />
                    Owner Name: @NullHandler.GetString(_Row["OwnerName"])<br />
                    @*Test Status: @MvcHtmlString.Create(WebUtil.GetTestStatusString(NullHandler.GetInt(_Row["TestStatus"])))*@
                </div>
                <div>
                    <a class="btn btn-mini" href="/Private/TestResult/Confirm/@_ID?VehicleID=@_VehicleID"><i class="icon-print"></i> Print</a>
                    @if(UserInfo.CanEditTestResult(_HasConfirmed, _HasPublished)){
                        <a class="btn btn-mini" href="/Private/TestResult/Edit/@_ID?VehicleID=@_VehicleID"><i class="icon-edit"></i> Edit</a>
                    }
                </div>
            </div>
        }
    }
}